package gew.system;

import gew.metadata.Queries;
import gew.services.DimensionValueService;
import gew.utils.SqlUtils;
import javax.servlet.http.HttpServletRequest;

public class RequestParameterTreeCountriesInit extends RequestParameterTree {

    public RequestParameterTreeCountriesInit(HttpServletRequest request, DimensionValueService dvs) {
        super(request, dvs);
    }

    private String countryUrlCode;

    private String getCountryUrlCode(final HttpServletRequest request) {
        if (SqlUtils.EMPTY.equals(countryUrlCode == null ? SqlUtils.EMPTY : countryUrlCode)) {
            countryUrlCode = getInitCountryUrlCode(request, getParams(), getLocale());
        }
        return countryUrlCode;
    }

    @Override
    void initFilterCode(final HttpServletRequest request) {
        filterCode = (new Integer(Constants.HIER_GROUP_COUNTRY)).toString();
    }

    @Override
    void initFilterRequestType(final HttpServletRequest request) {
        filterRequestType = Constants.FILTER_REQUEST_INIT;
    }

    @Override
    void initUrlTemplate(final HttpServletRequest request) {
        StringBuilder buf = new StringBuilder();
        buf
                .append(SqlUtils.VERTICAL_BAR)
                .append(getLocaleUrlCode())
                .append(SqlUtils.VERTICAL_BAR)
                .append(Constants.SECTION_INDICATORS)
                .append(SqlUtils.VERTICAL_BAR)
                .append(getInitIndicatorUrlCode(request, getParams(), getLocale()))
                .append(SqlUtils.VERTICAL_BAR)
                .append(SqlUtils.AT)
                .append(getCountryUrlCode(request))
                .append(SqlUtils.AT)
                .append(SqlUtils.VERTICAL_BAR);
        urlTemplate = buf.toString();
    }

    @Override
    void initSelectedIdsCS(final HttpServletRequest request, final DimensionValueService dvs) {
        selectedIdsCS = dvs.getIdsCSByUrlCode(getLocale(), getCountryUrlCode(request), Queries.CountryDimensionValue);
    }

}
